import { create } from "zustand";
import type { RepositoryBranch } from "../types/projectTypes";
import * as api from '../api/branchApi';

type BranchState = {
    branchsDict: Record<number, RepositoryBranch[]>;
    loadBranches: (projectId: number) => Promise<void>;
}
export const useBranchStore = create<BranchState>((set) => ({
    branchsDict: {},
    async loadBranches(projectId: number) {
        const data = await api.getBranches(projectId);
        set((state) => ({
            branchsDict: {
                ...state.branchsDict,
                [projectId]: data.data
            }
        }));
    }
}));
